﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Requisition_Approve : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        D_Requisition d_request = new D_Requisition();
        M_Requisition m_request = new M_Requisition();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadToStatusCombo();
                cmbStatusRequest.Text = "รอการอนุมัติ";
                LoadGrid();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
        }
        protected void grdRequisition_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
              LoadGrid();
        }
        protected void grdRequisition_ItemCommand(object sender, GridCommandEventArgs e)
        {

        }
        private void LoadGrid()
        {
            grdRequisition.DataSource = d_request.GetListForApproveFillByEmpSeq(cn.ApproveID, cmbStatusRequest.Text);
          //  grdRequisition.DataBind();
        }
        protected void cmbStatusRequest_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadGrid();
            grdRequisition.Rebind();

            Int32 count = 0;
            count = grdRequisition.Items.Count;
            Int32 i;

            if (count > 0)
            {
                if (cmbStatusRequest.Text == "รอการอนุมัติ")
                {
                    grdRequisition.Items[0].Enabled = true;
                }
                else
                {
                    for (i = 0; i < count; i++)
                    {
                        grdRequisition.Items[i].Enabled = false;
                    }
                }
            }
        }
        private void LoadToStatusCombo()
        {
            RadComboBoxItem item0 = new RadComboBoxItem("รอการอนุมัติ", "");
            cmbStatusRequest.Items.Insert(0, item0);
            RadComboBoxItem item1 = new RadComboBoxItem("อนุมัติแล้ว", "1");
            cmbStatusRequest.Items.Insert(1, item1);
            RadComboBoxItem item2 = new RadComboBoxItem("รายการตีกลับ", "2");
            cmbStatusRequest.Items.Insert(2, item2);
            RadComboBoxItem item3 = new RadComboBoxItem("รายการทั้งหมด", "3");
            cmbStatusRequest.Items.Insert(3, item3);
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            grdRequisition.DataSource = d_request.GetListForApproveFillByEmpSeq(cn.ApproveID,"รอการอนุมัติ");
            grdRequisition.Rebind();
        }
    }
}
